<template>
	<div class="flexcenter">
		<div class="max_width paddingtb">
			<div class="ffffff radius mainpadding">
				<div class="flexleft">
					<div :class="tabActive==index?'active margin_right3':'noActive margin_right3'"
						v-for="(item,index) in tabList" :key="index" @click="changeTab(index)">
						{{item.name}}
					</div>
				</div>
			</div>
			<!-- 优课 -->
			<div class="flexbetween flex_wrap" v-show="tabActive==0">
				<course v-for="item in list.data" :key="item.id" :child="item"></course>
			</div>
			<!-- 辅导、资料 -->
			<div class="flexbetween flex_wrap" v-show="tabActive==1||tabActive==3">
				<information v-for="item in list.data" :child="item"></information>
			</div>
			<!-- 测试 -->
			<div class="flexbetween flex_wrap" v-show="tabActive==2">
				<test-child v-for="item in list.data" :key="item.id" :child="item"></test-child>
			</div>
			<div class="flexbetween flex_wrap" v-show="tabActive==4">
				<teacher-list v-for="item in list.data" :key="item.id" :child="item"></teacher-list>
			</div>
			<div class="flexcenter margin_top" v-if="list.total > 15">
				<el-pagination background layout="prev, pager, next" :page-size="15" :total="list.total"
					@current-change="listChange">
				</el-pagination>
			</div>
		</div>
	</div>
</template>

<script>
	import { getCourse } from "@/API/home"
	import { teacher_getlist } from "@/API/question"
	import course from "@/views/fineCourse/components/course"
	import information from "@/views/information/components/information"
	import testChild from "@/views/test/components/testChild"
	import teacherList from "@/views/teacher/teacherList"
	export default {
		components: {
			course,
			information,
			testChild,
			teacherList
		},
		data() {
			return {
				tabActive: 0,
				tabList: [{
					name: "优课",
				}, {
					name: "辅导",
				}, {
					name: "测试",
				}, {
					name: "资料",
				}, {
					name: "老师",
				}],
				list: {
					data: []
				},
				keywords: ""
			}
		},
		created() {
			this.keywords=this.$route.query.keywords
			this.$bus.$on("searchmsg", data => {
				this.keywords=data
				this.getList()
			})
			this.getList()
		},
		methods: {
			async getList(page) {
				if (this.tabActive != 4) {
					this.list = { data: [] }
					let res = await getCourse({
						page: page || 1,
						type: this.tabActive + 1,
						keywords: this.keywords
					})
					this.list = res.data.data
					this.list.data = res.data.data.data
				} else {
					this.list = { data: [] }
					let res = await teacher_getlist({
						page: page || 1,
						keywords: this.keywords
					})
					this.list = res.data.data
					this.list.data = res.data.data.data
				}
			},
			listChange(val) {
				console.log(val)
				this.getCourseList(val)
			},
			changeTab(index) {
				this.keywords=""
				this.tabActive = index
				this.getList()
			}
		},
	}
</script>

<style lang="scss" scoped>
	.noActive {
		font-size: 15px;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}

	.active {
		font-size: 15px;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #3478F5;
		position: relative;
	}

	.active::after {
		content: '';
		width: 22px;
		height: 2px;
		background: #3478F5;
		border-radius: 6px 6px 6px 6px;
		position: absolute;
		left: 50%;
		transform: translateX(-50%);
		bottom: -10px;
	}
</style>